define [
  'chaplin'
], (Chaplin) ->

  'use strict'

  class BaseModel extends Chaplin.Model

    # Additional Attributes
    # =============================================================

    # Save the model as JSON
    saveAsJSON: ->
      json = do @toJSON
      promise = $.Deferred()

      type = if @id? then 'update' else 'create'
      # json._method = 'PUT' if type is 'update'

      ajaxPromise = Backbone.sync type, @,
        url: do @url
        dataType: 'json'
        contentType: 'application/json; charset=UTF-8'
        data: window.JSON.stringify json

      # Ajax promise
      ajaxPromise
        .fail =>
          promise.reject.apply @, arguments
        .done (json, status, ajaxObj) =>
          promise.resolve.apply @, [json, ajaxObj]

      # Return the promise
      promise

    fetch: ->
      @fetched = true
      super